package de.hsf.bp.netdoc;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.GridLayout;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Component;
import javax.swing.Box;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JList;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GUITest2 extends JFrame {

	private Network myNetwork;
	private JPanel contentPane;
	private JTextField txtFManu;
	private JTextField txtFModel;
	private JTextField txtFSNr;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		
		
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GUITest2 frame = new GUITest2();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public GUITest2() {
		
		initNetwork();
		
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnProject = new JMenu("Project");
		menuBar.add(mnProject);
		
		JMenuItem mntmNewProject = new JMenuItem("New Project");
		mnProject.add(mntmNewProject);
		
		JMenuItem mnLoadProject = new JMenuItem("Load Project");
		mnProject.add(mnLoadProject);
		
		JMenuItem mntmSaveProject = new JMenuItem("Save Project");
		mnProject.add(mntmSaveProject);
		
		JMenuItem mntmSaveAs = new JMenuItem("Save As...");
		mnProject.add(mntmSaveAs);
		
		JMenuItem mntmProperties = new JMenuItem("Properties");
		mnProject.add(mntmProperties);
		
		JMenuItem mntmQuit = new JMenuItem("Quit");
		mnProject.add(mntmQuit);
		
		JMenu mnComponents = new JMenu("Components");
		menuBar.add(mnComponents);
		
		JMenuItem mntmViewEdit = new JMenuItem("View / Edit Components");
		mnComponents.add(mntmViewEdit);
		
		JMenuItem mntmEditProperties = new JMenuItem("Edit Properties");
		mnComponents.add(mntmEditProperties);
		
		JMenuItem mntmViewConnections = new JMenuItem("View Connections");
		mnComponents.add(mntmViewConnections);
		
		JMenu mnActions = new JMenu("Actions");
		menuBar.add(mnActions);
		
		JMenuItem mntmGetComponentInfo = new JMenuItem("Get Component Info");
		mnActions.add(mntmGetComponentInfo);
		
		JMenuItem mntmShowRoute = new JMenuItem("Show Route");
		mnActions.add(mntmShowRoute);
		
		JMenu mnAbout = new JMenu("About");
		menuBar.add(mnAbout);
		
		JMenu mnHelp = new JMenu("Help");
		mnAbout.add(mnHelp);
		
		JMenuItem mntmNetworkModel = new JMenuItem("Network Model");
		mnHelp.add(mntmNetworkModel);
		
		JMenuItem mntmAbout = new JMenuItem("About...");
		mnAbout.add(mntmAbout);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblAddComponent = new JLabel("ADD COMPONENT");
		lblAddComponent.setBounds(36, 11, 127, 17);
		lblAddComponent.setFont(new Font("Tahoma", Font.BOLD, 14));
		contentPane.add(lblAddComponent);
		
		JLabel lblManufacturer = new JLabel("Manufacturer");
		lblManufacturer.setBounds(36, 37, 127, 14);
		contentPane.add(lblManufacturer);
		
		txtFManu = new JTextField();
		txtFManu.setBounds(169, 34, 620, 20);
		contentPane.add(txtFManu);
		txtFManu.setColumns(10);
		
		JLabel lblModel = new JLabel("Model");
		lblModel.setBounds(36, 63, 28, 14);
		contentPane.add(lblModel);
		
		txtFModel = new JTextField();
		txtFModel.setBounds(169, 60, 620, 20);
		contentPane.add(txtFModel);
		txtFModel.setColumns(10);
		
		JLabel lblSerialNo = new JLabel("Serial No.");
		lblSerialNo.setBounds(36, 89, 46, 14);
		contentPane.add(lblSerialNo);
		
		txtFSNr = new JTextField();
		txtFSNr.setBounds(169, 86, 620, 20);
		txtFSNr.setColumns(10);
		contentPane.add(txtFSNr);
		
		JLabel lblConnectedTo = new JLabel("Connected to...");
		lblConnectedTo.setBounds(36, 230, 127, 14);
		contentPane.add(lblConnectedTo);
		
		JList list = new JList();
		list.setBounds(169, 137, 620, 201);
		contentPane.add(list);
		
		
		// Hier hab ich in der ActionPerformed rumgepfuscht
		JButton btnCreateAndAdd = new JButton("Create and Add");
		btnCreateAndAdd.setBounds(36, 469, 127, 23);
		btnCreateAndAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Client newClient = new Client();
				newClient.setManufacturer(txtFManu.getText());
				newClient.setModel(txtFModel.getText());
				//newClient.setSerialnr(txtFSNr.getText()); // float aus TXTFeld auslesen?
				myNetwork.addClient(newClient);
			}
		});
		contentPane.add(btnCreateAndAdd);
		
		JButton btnShowClients = new JButton("Show Clients");
		btnShowClients.setBounds(36, 523, 127, 23);
		btnShowClients.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				myNetwork.showClientsOnConsole();
			}
		});
		contentPane.add(btnShowClients);
	}
	
	
	
	
	
	public void initNetwork(){
		if (myNetwork == null)
			myNetwork = new Network();
	}

}
